<?php
declare(strict_types=1);
namespace app\admin\service\login;

use app\admin\model\Admin;
use app\admin\model\AdminLog;
use app\admin\model\AdminRole;
use app\admin\model\AdminRule;
use app\common\jwt\Auth;

class IndexService  {

    /**
     * 管理员登录
    */
    public static function adminLogin($params){
        $user = Admin::where('username',$params['username'])->find();

        if($user){
            if($user->pwd != md5($params['pwd'])){
                return suc('密码错误','',0);
            }
            if($user->state == 0){
                return suc('账号已停用','',0);
            }
            $user->token = (new Auth())->signToken($user->id); //更新token
            (new AdminLog())->loginLog($user->id);

            return suc('登录成功',$user);
        }
        return suc('用户不存在','',0);
    }

}